<?php

if (!defined('BASEPATH'))
	exit('No direct script access allowed');
/**
 * CodeIgniter
 *
 * An open source application development framework for PHP 5.1.6 or newer
 *
 * @package		CodeIgniter
 * @author		ExpressionEngine Dev Team
 * @copyright	Copyright (c) 2008 - 2011, EllisLab, Inc.
 * @license		http://codeigniter.com/user_guide/license.html
 * @link		http://codeigniter.com
 * @since		Version 1.0
 * @filesource
 */
// ------------------------------------------------------------------------

/**
 * CodeIgniter Application Controller Class
 *
 * This class object is the super class that every library in
 * CodeIgniter will be assigned to.
 *
 * @package		CodeIgniter
 * @subpackage	Libraries
 * @category	Libraries
 * @author		ExpressionEngine Dev Team
 * @link		http://codeigniter.com/user_guide/general/controllers.html
 */
class CI_Controller {

	private static $instance;

	/**
	 * Constructor
	 */
	public function __construct() {
		self::$instance = & $this;

		// Assign all the class objects that were instantiated by the
		// bootstrap file (CodeIgniter.php) to local class variables
		// so that CI can run as one big super object.
		foreach (is_loaded() as $var => $class) {
			$this->$var = & load_class($class);
		}

		$this->load = & load_class('Loader', 'core');

		$this->load->initialize();

		$this->result = array();

		$this->return = TRUE; //返回结果 TRUE：json字符串  FALSE：模版

		log_message('debug', "Controller Class Initialized");
	}

	public function _remap($method, $params = array()) {
		$this->xhprof_enable();
		$this->$method();
		$this->xhprof_disable();

		$this->load->json($this->result);
	}

	public static function &get_instance() {
		return self::$instance;
	}

	protected function xhprof_enable() {
		xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
	}

	protected function xhprof_disable() {
		$xhprof_data = xhprof_disable();
// display raw xhprof data for the profiler run
		//echo __LINE__;
		//print_r($xhprof_data);

		$XHPROF_ROOT = '/home/hotel/work/sys/xhprof-0.9.2';
		include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
		include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";
// save raw data for this profiler run using default
// implementation of iXHProfRuns.
		$xhprof_runs = new XHProfRuns_Default();
// save the run under a namespace "xhprof_foo"
		$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof");
		/*
		  echo "---------------\n" .
		  "Assuming you have set up the http based UI for \n" .
		  "XHProf at some address, you can view run at \n" .
		  "http://test.local/xhprof/xhprof_html/index.php?run=$run_id&source=xhprof\n" .
		  "---------------\n";
		 * 
		 */
		$this->result['xh'] = 'http://192.168.1.50/work/xhprof/xhprof_html/index.php?run=' . $run_id . '&source=xhprof';
	}

}

// END Controller class

/* End of file Controller.php */
/* Location: ./system/core/Controller.php */